﻿using Abp;
using Abp.Dependency;
using Abp.Quartz.Configuration;
using Quartz;
using Topshelf;

namespace Hengyuantong.SmartRail.Services
{
    public class ServiceRunner : ServiceControl, ServiceSuspend
    {
        readonly IScheduler scheduler;
        //readonly IConsumerService consumerService;

        public ServiceRunner()
        {
            scheduler = IocManager.Instance.ResolveAsDisposable<IAbpQuartzConfiguration>().Object.Scheduler;
            //consumerService = IocManager.Instance.ResolveAsDisposable<IConsumerService>().Object;
        }

        public bool Continue(HostControl hostControl)
        {
            scheduler.ResumeAll();
            return true;
        }

        public bool Pause(HostControl hostControl)
        {
            scheduler.PauseAll();
            return true;
        }

        public bool Start(HostControl hostControl)
        {
            scheduler.Start();
            //consumerService.Start();
            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            scheduler.Shutdown(false);
            //consumerService.Stop();
            return true;
        }
    }
}